<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link href="${ctxPath!}/layui/css/layui.css" rel="stylesheet" type="text/css">
    <% include("/templates/common/dialog.html"){} %>
</head>
<div style="padding:10px 50px 10px 10px">
    <form id="clientForm" method="post" action="${ctxPath!}/sys/client/edit" class="layui-form layui-row">
        <div style="margin-bottom:20px;font-size:14px;border-bottom:1px solid #ccc; padding-bottom: 5px;">用户信息</div>
        <div class="layui-col-md6">
            <input type="hidden" name="id" value="${client.id}"/>
            <input type="hidden" name="userId" value="${client.userId}"/>
            <div class="layui-form-item">
                <label class="layui-form-label">用户名称</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="username" value="${client.username}" lay-verify="required" />
                </div>
            </div>
            <!--编辑时不显示-->
            <% if(client.id == null || client.id <= 0){  %>
            <div class="layui-form-item">
                <label class="layui-form-label">用户账号</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="account" value="${client.account}" lay-verify="required"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">用户密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" id="password" type="password" name="password" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input class="layui-input" id="r_password" type="password" name="r_password" lay-verify="required" />
                </div>
            </div>
            <% } %>

            <div class="layui-form-item">
                <label class="layui-form-label">电话</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="telephone" value="${client.telephone}" lay-verify="required|phone" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">住址</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="address" value="${client.address}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">生日</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" id="birthday" name="birthday" value="${client.birthday!,dateFormat="yyyy-MM-dd"}" lay-verify="required|date"  readonly/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="email" value="${client.email}" lay-verify="required|email" />
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">来源</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="source" value="${client.source}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">预定时间</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" id="dueDate" name="dueDate" value="${client.dueDate!,dateFormat="yyyy-MM-dd"}" lay-verify="required|date"  readonly/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">需求时间</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" id="demandDate" name="demandDate" value="${client.demandDate!,dateFormat="yyyy-MM-dd"}" lay-verify="required|date"  readonly/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">需求内容</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="demandContent" value="${client.demandContent}" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">期望城市</label>
                <div class="layui-input-block">
                    <input class="layui-input" type="text" name="expectedCity" value="${client.expectedCity}" lay-verify="required" />
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">老用户</label>
                <div class="layui-input-block">
                    <select name="old" id="old">
                        <option value="1" ${client.old == true ? "selected" : ""}>是</option>
                        <option value="0" ${client.old == false ? "selected" : ""}>否</option>
                    </select>
                </div>
            </div>


        </div>
        <div class="layui-form-item" style="text-align: center;">
            <div class="layui-input-block">
                <button id="submitButton" class="layui-btn" lay-submit lay-filter="*">保存</button>
                <button type="button" class="layui-btn layui-btn-primary" onclick="closeAll()">取消</button>
            </div>
        </div>
    </form>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js?v=1.0.1"></script>
<script type="text/javascript">
    layui.use(['form','laydate'], function(){
        var form = layui.form;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birthday' //指定元素
        });
        laydate.render({
            elem: '#dueDate' //指定元素
        });
        laydate.render({
            elem: '#demandDate' //指定元素
        });
        form.on('submit(*)', function(data){
            var clientId = '${client.id}';
            if(!clientId){
                if($('#password').val() != $('#r_password').val()){
                    layer.alert("两次输入的密码不相同", {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                    return false;
                }
            }
            $.post($("#clientForm").attr("action"), $("#clientForm").serialize(), function(data){
                if(data.status == 200){
                    layer.alert(data.msg, {
                        icon: 1,
                        skin: 'layer-ext-moon'
                    },function () {
                        parent.myJqGrid.reloadGrid({});
                        parent.layer.closeAll();
                    });
                }else{
                    layer.alert(data.msg, {
                        icon: 2,
                        skin: 'layer-ext-moon'
                    });
                }
            });
            return false; //阻止表单跳转。
        });
        form.on('select(orgId)', function(data){
            console.log(data.elem); //得到select原始DOM对象
            console.log(data.value); //得到被选中的值
            console.log(data.othis); //得到美化后的DOM对象
            $.post("/sys/role/getRoles",{"orgId":data.value},function(data){
                var html="";
                var roles=data.roles;
                for(var i=0;i<roles.length;i++){
                    html+='<option value="'+roles[i].id+'">'+roles[i].name+'</option>';
                }
                $("#rid").html(html);
                form.render('select'); //刷新select选择框渲染
            },"json");
        });
    });
    function closeAll() {
        parent.layer.closeAll();
    }
</script>